<?php
/*
	获取代理商代理地区
*/
defined('BY_JYA') or exit('error');
list($mid)=$arguments;
$agents=$this->getall('agent',array('mid'=>$mid));
	$areas=array();
	foreach($agents as $agent){
		if($agent['type']==1){
			//省级代理
			$province=pdo_get('core_area',array('code'=>$agent['area_code']));
			$citys=pdo_getall('core_area',array('parent_code'=>$province['code']),array(),'title');
			foreach($citys as &$city){
				$city=pdo_getall('core_area',array('parent_code'=>$city['code']),array('title'));
				foreach($city as &$dis){
					$dis=$dis['title'];
				}
			}
			$areas[$province['title']]=$citys;
		}
		if($agent['type']==2){
			//市级代理
			
			$city=pdo_get('core_area',array('code'=>$agent['area_code']));
			$province=pdo_get('core_area',array('code'=>$city['parent_code']));
			$districts=pdo_getall('core_area',array('parent_code'=>$city['code']),array('title'),'title');
			foreach($districts as &$dis){
				$dis=$dis['title'];
			}
			$areas[$province['title']][$city['title']]=$districts;
		}
		/*if($agent['type']==3){
			//县级代理
			
			$district=pdo_getcolumn('core_area',array('code'=>$agent['area_code']));
			$city=pdo_getcolumn('core_area',array('code'=>$district['parent_code']));
			$province=pdo_getcolumn('core_area',array('code'=>$city['parent_code']));
			
			$areas[$province['title']][$city['title']][]=$district['title'];
		}*/
	}
	return $areas;